home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 2001 May / macformat_103_may_2001.iso / Mac OS X Shareware / Fizilla / Chrome / toolkit.jar / content / global / finddialog.js < prev    next >
Encoding:
JavaScript  |  2001-03-26  |  3.5 KB  |  123 lines

  1. /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public
  4.  * License Version 1.1 (the "License"); you may not use this file
  5.  * except in compliance with the License. You may obtain a copy of
  6.  * the License at http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the License is distributed on an "AS
  9.  * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10.  * implied. See the License for the specific language governing
  11.  * rights and limitations under the License.
  12.  *
  13.  * The Original Code is Mozilla Communicator client code, released March
  14.  * 31, 1998.
  15.  *
  16.  * The Initial Developer of the Original Code is Netscape Communications
  17.  * Corporation. Portions created by Netscape are
  18.  * Copyright (C) 1998 Netscape Communications Corporation. All
  19.  * Rights Reserved.
  20.  *
  21.  * Contributor(s): Alec Flett       <alecf@netscape.com>
  22.  *                 Bill Law         <law@netscape.com>
  23.  *                 Blake Ross       <blakeross@telocity.com>
  24.  *                 Matt Fisher      <matt@netscape.com>
  25.  *                 Simon Fraser     <sfraser@netscape.com>
  26.  *                 Stuart Parmenter <pavlov@netscape.com>
  27.  */
  28.  
  29. var finder; // Find component.
  30. var data;   // Search context (passed as argument).
  31. var dialog; // Quick access to document/form elements.
  32.  
  33. function initDialogObject()
  34. {
  35.   // Create dialog object and initialize.
  36.   dialog = new Object;
  37.   dialog.findKey         = document.getElementById("dialog.findKey");
  38.   dialog.caseSensitive   = document.getElementById("dialog.caseSensitive");
  39.   dialog.wrap            = document.getElementById("dialog.wrap");
  40.   dialog.searchBackwards = document.getElementById("dialog.searchBackwards");
  41.   dialog.find            = document.getElementById("ok");
  42.   dialog.bundle          = null;
  43. }
  44.  
  45. function fillDialog()
  46. {
  47.   // Set initial dialog field contents.
  48.   dialog.findKey.value = data.searchString;
  49.  
  50.   dialog.caseSensitive.checked   = data.caseSensitive;
  51.   dialog.wrap.checked            = data.wrapSearch;
  52.   dialog.searchBackwards.checked = data.searchBackwards;
  53. }
  54.  
  55. function loadData()
  56. {
  57.   // Set data attributes per user input.
  58.   data.searchString    = dialog.findKey.value;
  59.   data.caseSensitive   = dialog.caseSensitive.checked;
  60.   data.wrapSearch      = dialog.wrap.checked;
  61.   data.searchBackwards = dialog.searchBackwards.checked;
  62. }
  63.  
  64. function onLoad()
  65. {
  66.   initDialogObject();
  67.  
  68.   // Get find component.
  69.   finder = Components.classes["@mozilla.org/appshell/component/find;1"].getService();
  70.   finder = finder.QueryInterface(Components.interfaces.nsIFindComponent);
  71.  
  72.   // Change "OK" to "Find".
  73.   dialog.find.label = document.getElementById("fBLT").getAttribute("label");
  74.  
  75.   // Setup the dialogOverlay.xul button handlers.
  76.   doSetOKCancel(onOK, onCancel);
  77.  
  78.   // Save search context.
  79.   data = window.arguments[0];
  80.  
  81.   // Tell search context about this dialog.
  82.   data.findDialog = window;
  83.  
  84.   fillDialog();
  85.  
  86.   doEnabling();
  87.  
  88.   if (dialog.findKey.value)
  89.     dialog.findKey.select();
  90.   else
  91.     dialog.findKey.focus();
  92. }
  93.  
  94. function onUnload() {
  95.   // Disconnect context from this dialog.
  96.   data.findDialog = null;
  97. }
  98.  
  99. function onOK()
  100. {
  101.   // Transfer dialog contents to data elements.
  102.   loadData();
  103.  
  104.   // Search.
  105.   var result = finder.findNext(data);
  106.   if (!result) {
  107.     if (!dialog.bundle)
  108.       dialog.bundle = document.getElementById("findBundle");
  109.     window.alert(dialog.bundle.getString("notFoundWarning"));
  110.   }
  111. }
  112.  
  113. function onCancel()
  114. {
  115.   // Close the window.
  116.   return true;
  117. }
  118.  
  119. function doEnabling()
  120. {
  121.   dialog.find.disabled = !dialog.findKey.value;
  122. }
  123.